<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <title>新增用户</title>
    <link rel="stylesheet" type="text/css" href="./css/main.css" />
    <link rel="stylesheet" type="text/css" href="./layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="./css/layuiAdminTheme.css" />
    <style type="text/css">

    </style>
  </head>
  <body>
    <script src="./js/main.js" charset="utf-8"></script>
<!--    <script src="https://cdn.jsdelivr.net/npm/jquery" charset="utf-8"></script>-->
    <script src="./layui/layui.js" charset="utf-8"></script>
    <script src="./js/jQuery.main.js"></script>

    <form class="layui-form" action="" lay-filter="data">

      <div class="layui-form-item">
          <label class="layui-form-label" style="width: 8em;">用户名：</label>
        <input id="name" type="text" name="userName" lay-verify="required" autocomplete="" class="layui-input" style="width: 15em;" placeholder="请输入用户名">
      </div>

      <div class="layui-form-item">
            <label class="layui-form-label" style="width: 8em;">登录名(工号)：</label>
        <input id="loginN" type="text" name="loginName" lay-verify="required" autocomplete="" class="layui-input" style="width: 15em;" placeholder="请输入登录名（建议使用工号）">
<!--        <textarea placeholder="请输入登录名（建议使用工号）" class="layui-textarea" name="loginName" lay-verify="required" maxlength="255"></textarea>-->
      </div>

      <div class="layui-form-item" >
          <label class="layui-form-label" style="width: 8em;">部门选择：</label>
        <div class="layui-input-inline " style="width: 15em">
          <select name="deptId" id="deptId" lay-verify="required" lay-filter="deptId" lay-search="">
            <option value="">请选择部门...</option>
          </select>
        </div>
        </div>
      <div id="desc"></div>

      <div class="layui-form-item" >
        <label class="layui-form-label" style="width: 8em;">权限赋予：</label>
        <div class="layui-input-inline " style="width: 15em">
          <select name="type" id="type" lay-verify="required" lay-filter="type" lay-search="">
            <option value="">请赋予权限...</option>
            <option value="1">超级管理员</option>
            <option value="0">二级管理员</option>
            <option value="2">普通作业员</option>
          </select>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 8em;">设置密码：</label>
        <input id="psw" type="text" name="password" lay-verify="required" autocomplete="" class="layui-input" style="width: 15em;" placeholder="请设置密码">
<!--        <textarea placeholder="请输入登录名（建议使用工号）" class="layui-textarea" name="password" lay-verify="required" maxlength="255"></textarea>-->
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label" style="width: 8em;">再次确认密码：</label>
        <input id="psw2" type="text" name="password2" lay-verify="required" autocomplete="" class="layui-input" style="width: 15em;" placeholder="请再次输入密码">
        <!--        <textarea placeholder="请输入登录名（建议使用工号）" class="layui-textarea" name="password" lay-verify="required" maxlength="255"></textarea>-->
      </div>



      <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <button type="button" class="layui-btn" lay-submit='' >新增用户</button>
      </div>


    </form>

    <script type="text/javascript">
      var form = null;


      layui.use(['form',"layer"], function() {
        var form=layui.form;
        var layer = layui.layer;
        $.ajax({
          url: url + '/sys-dept/listDept',
          method: 'POST',
          contentType: 'application/json',
          success: function(res) {
            if (res.code == 200) {
              for (var i = 0; i < res.data.length; i++) {
                $("#deptId").append("<option value='" + res.data[i].id + "'>" + res.data[i].dept +
                        "</option>");
              }
              form.render('select');
            }
          }
        })

        form.on('submit', function() {
          var data = form.val('data');
          data.userName =$('#name').val();
          data.loginName =$('#loginN').val();
          data.password =$('#psw').val();
          data.deptId=$('#deptId').val();
          data.createUserId=sessionStorage.getItem('userId');
          let confirm1=layer.confirm('确定新增用户吗？', {
            btn: ['确定','取消']
          },function () {
            if ($('#psw').val() !=$('#psw2').val()){
              layer.msg('两次密码不一致!请注意确认');
            }
            else
              {
              $.ajax({
                url: url + '/sys-user/add',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(data),
                success: function (res) {
                  parent.layer.alert(res.msg);
                  if (res.code == 200) parent.switchNav(0);
                }
              })
              layer.close(confirm1);
            }
          },function (){
            layer.close(confirm1);
          })
        });
      })

    </script>
  </body>
</html>
